<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>demo1</title>
    <style type="text/css">
        .box{
        	width: 20px;
            height: 20px;
            background-color: red;
            position: absolute;
        }
    </style>
</head>
<body>
     <div class="box" id="box">
     	
     </div>
</body>
<script type="text/javascript">
     //在火狐下部支持var height = document.getElementById("box").style.height;这种写法
     var width =  parseInt(document.getElementById("box").offsetWidth);
     var height = parseInt(document.getElementById("box").offsetHeight);
     var tmp=0;
     function run(){
     	if(width<1){
     		tmp=0;
     	}else if(width>400){
            tmp=1;
     	}
     	if(tmp==0){
           width++;
           height++;
         }else if(tmp==1){
           width--;
           height--;
         }
        document.getElementById("box").style.width=width+"px";
        document.getElementById("box").style.height=height+"px";
     }
     setInterval(run,10);
</script>
</html>